package com.example.bishe.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bishe.entity.Record;
import com.example.bishe.mapper.RecordMapper;
import com.example.bishe.service.RecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  标签服务实现类
 * </p>
 *
 * @author LDH
 * @since 2022/11/30
 */
@Service
public class RecordServiceImpl extends ServiceImpl<RecordMapper, Record> implements RecordService {

    @Autowired
    private RecordMapper recordMapper;

    /**
    * 功能描述: 分页查询用户一级记录
    * @Param: [pageNum, pageSize, userId, title, type]
    * @return: com.baomidou.mybatisplus.core.metadata.IPage<com.example.bishe.entity.Record>
    * @Author: LDH
    * @Date: 2023/03/19
    */
    @Override
    public IPage<Record> getPage(int pageNum, int pageSize, Long userId, String title, Integer type, Integer show) {
        Page<Record> page = new Page<>(pageNum, pageSize);
        return recordMapper.getPage(page, title, userId, type, show);
    }

    /**
    * 功能描述: 添加标签
    * @Param: [userId, title, type, description]
    * @return: void
    * @Author: LDH
    * @Date: 2023/04/18
    */
    @Override
    public void add(Record record) {
        Record record1 = new Record();
        record1.setType(record.getType());
        record1.setDescription(record.getDescription());
        record1.setTitle(record.getTitle());
        record1.setUserId(record.getUserId());
        recordMapper.insert(record1);
    }

    /**
    * 功能描述: 删除标签
    * @Param: [ids]
    * @return: void
    * @Author: LDH
    * @Date: 2023/04/18
    */
    @Override
    public void delete(List<Long> ids) {
        if (ids.isEmpty()) return;
        recordMapper.deleteBatchIds(ids);
    }
}
